package com.woniuxy.school.dietary.comment.controller;


import com.woniuxy.commons.core.model.Result;
import com.woniuxy.commons.core.util.JwtUtil;
import com.woniuxy.school.dietary.comment.model.from.AddCommentFrom;
import com.woniuxy.school.dietary.comment.model.from.ReplyCommentFrom;
import com.woniuxy.school.dietary.comment.service.CommentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2025年05月14日
 */
@RestController
@RequestMapping("/commentInfo")
@Api(tags = "膳食评论模块")
public class CommentInfoController {
    @Resource
    private CommentInfoService commentInfoService;
    /**
     * 用户评论商家
     */
    @PostMapping("/addComment")
    @ApiOperation(value = "用户评论商家")
    public Result commentInfoService(@RequestBody AddCommentFrom from, BindingResult br, @RequestHeader String token) throws Exception {
        //从token中取出用户id
        String string = JwtUtil.parseUserToken(token).get("userId").toString();
        commentInfoService.commentInfoService(from,Long.valueOf(string));
        return Result.getResult().setCode(200).setMessage("评论成功");

    }
    /**
     * 商家回复用户评论
     */
    @PostMapping("/replyComment")
    @ApiOperation(value = "商家回复用户评论")
    public Result replyComment(@RequestBody ReplyCommentFrom from, BindingResult br, @RequestHeader String token) throws Exception {
        //从token中取出用户id
        String string = JwtUtil.parseUserToken(token).get("userId").toString();
        commentInfoService.replyComment(from,Long.valueOf(string));
        return Result.getResult().setCode(200).setMessage("回复成功");

    }


}

